﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinCell.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win cell.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win cell.
    /// </summary>
    public class CuitWinCell : CuitWinControl<WinCell>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinCell" /> class.
        /// </summary>
        public CuitWinCell()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinCell(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinCell(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinCell(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinCell(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinCell(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="rowIndex">
        /// The row index.
        /// </param>
        /// <param name="colIndex">
        /// The col index.
        /// </param>
        public CuitWinCell(UITestControl testControl, int rowIndex, int colIndex)
            : this(testControl, "RowIndex=" + rowIndex + ";ColumnIndex=" + colIndex)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinCell"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="rowIndex">
        /// The row index.
        /// </param>
        /// <param name="colIndex">
        /// The col index.
        /// </param>
        public CuitWinCell(ICuitControlBase wrappedControl, int rowIndex, int colIndex)
            : this(wrappedControl.GetMicrosoftTestControl(), rowIndex, colIndex)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets a value indicating whether checked.
        /// </summary>
        public bool Checked
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Checked;
            }
        }

        /// <summary>
        ///     Gets the column index.
        /// </summary>
        public int ColumnIndex
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.ColumnIndex;
            }
        }

        /// <summary>
        ///     Gets or sets a value indicating whether indeterminate.
        /// </summary>
        public bool Indeterminate
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Indeterminate;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.Indeterminate = value;
            }
        }

        /// <summary>
        ///     Gets the row index.
        /// </summary>
        public int RowIndex
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.RowIndex;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether selected.
        /// </summary>
        public bool Selected
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Selected;
            }
        }

        /// <summary>
        ///     Gets the value.
        /// </summary>
        public string Value
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Value;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The check.
        /// </summary>
        public void Check()
        {
            this._control.WaitForControlReady();
            if (!this._control.Checked)
            {
                this._control.Checked = true;
            }

            this.WriteTestOutput(string.Empty);
        }

        /// <summary>
        /// The set value.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        public void SetValue(string value)
        {
            this._control.WaitForControlReady();
            this.WriteTestOutput(value);
            this._control.Value = value;
        }

        /// <summary>
        ///     The un check.
        /// </summary>
        public void UnCheck()
        {
            this._control.WaitForControlReady();
            if (this._control.Checked)
            {
                this._control.Checked = false;
            }

            this.WriteTestOutput(string.Empty);
        }

        #endregion
    }
}